package com.xscha.soyue.common.core.utils;

import java.util.Random;
import java.util.UUID;

/**
 * 随机数扫描类
 *
 * @author Vondser
 * @version V2024.1.0
 */
public class RandomUtils {

	private static final Random RANDOM = new Random();

	private static final char[] CHARS = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM".toCharArray();

	private static final char[] NUMS = "0987654321".toCharArray();

	public static String next(int size) {
		StringBuilder sb = new StringBuilder(size);
		for (int i = 0; i < size; i++) {
			if (RANDOM.nextBoolean()) {
				sb.append(CHARS[nextInt(CHARS.length)]);
			}
			else {
				sb.append(NUMS[nextInt(NUMS.length)]);
			}
		}
		return sb.toString();
	}

	public static String next(int size, boolean upper) {
		return upper ? next(size).toUpperCase() : next(size).toLowerCase();
	}

	public static String nextChars(int size) {
		StringBuilder sb = new StringBuilder(size);
		for (int i = 0; i < size; i++) {
			sb.append(CHARS[nextInt(CHARS.length)]);
		}
		return sb.toString();
	}

	public static String nextChars(int size, boolean upper) {
		return upper ? nextChars(size).toUpperCase() : nextChars(size).toLowerCase();
	}

	public static String nextNums(int size) {
		StringBuilder sb = new StringBuilder(size);
		for (int i = 0; i < size; i++) {
			sb.append(NUMS[nextInt(NUMS.length)]);
		}
		return sb.toString();
	}

	public static String UUID() {
		return UUID.randomUUID().toString();
	}

	public static String pureUUID() {
		return UUID().replace("-", "");
	}

	public static int nextInt(int max) {
		return nextInt(0, max);
	}

	public static int nextInt(int min, int max) {
		return max == min ? max : (min + RANDOM.nextInt(max - min));
	}

}
